/* 跳转详情方法
_this this实例
prodType 产品类型
prodId 产品Id
courseType 课程类型
query 额外需要的参数对象(query.isList 0 默认跳转详情 1 跳转对应的列表)
isNeedAppPush 是否需要app跳转 默认0不需要 1需要
sortType: 数据排序 1按时间排序 2按观看次数排序
*/
export function goDetails(_this, prodType, prodId, query, courseType, isNeedAppPush = 0, sortType) {
  let toPath = getUrlDetail(prodType, prodId, query, courseType, sortType);
  if (!toPath) {
    return
  }
  let isIOSApp = navigator.userAgent.indexOf("IOSNewApp") > -1;
  let isAndoridNewApp = navigator.userAgent.indexOf("APPAndroidLogin") > -1;
  if ((isIOSApp || isAndoridNewApp) && isNeedAppPush == 1) {
    if (isIOSApp) {
      window.webkit.messageHandlers.iosWechatRoute.postMessage(toPath);
    } else {
      let data = {
        path: toPath
      }
      window.androidWechatRoute.doAction(JSON.stringify(data));
    }
  } else {
    _this.$routerGo(_this, "push", {path: toPath})
  }
}
// 获取需要跳转的路由详情
export function getUrlDetail(prodType, prodId, query, courseType, sortType) {
  let ckFrom = prodType;
  // 默认ckFrom 为 prodType， 如果需要另外赋值，需要在query.ckFrom赋值然后替换
  // (课程、专栏、训练营、题库、教务、预约才有ckFrom)，对应值为[5, 25, 30, 66, 9, 24, 26, 29, 38, 67, 103, 104, 78, 91, 146, 8076, 9078, 129, 9042, 116, 9043, 86]
  if (query && query.ckFrom) {
    ckFrom = ckFrom != query.ckFrom ? query.ckFrom : ckFrom;
    delete query.ckFrom;
  }
  // (砍价 || 拼团 || 限时购 || 好友助力) && 类型为vip或svip  需要跳转到vipCollage
  if (query && (query.isBargain || query.isCollage || query.isSales || query.isFa) && (prodType == global.ckFrom.vip || prodType == global.ckFrom.svip)) {
    prodType = global.ckFrom.vip ? global.ckFrom.collageVip : global.ckFrom.collageSvip;
  }
  // 判断是跳转详情还是列表
  if (query && query.isList) {
    prodType = query.isList == 1 ? (prodType + '-1') : prodType;
    delete query.isList;
  }
  // typeToUrl 的 key 是 config.js中对应的 global.ckFrom值
  let typeToUrl = {
    '1': `/member/vip/vipUp?type=${prodType}`,
    '5': `/homePage/course/${courseType == 0 ? 'video' : courseType == 1 ? 'voice' : 'imgText'}?courseId=${prodId}&ckFrom=${ckFrom}`,
    '7': `/activity/activityDetail?ActivityNo=${prodId}`,
    '8': `/homePage/datum/datumDetail?datumId=${prodId}`,
    '9': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '10': `/homePage/socialGroup/socialGroupInfo?SocialRoomId=${prodId}`,
    '11': `/homePage/examination/examinationDetail?ExaminationNo=${prodId}`,
    '12': `/mall/shopDetail/shopDetail?shopNo=${prodId}`,
    '15': `/homePage/qa/questionDetail?answerId=${prodId}`,
    '16': `/homePage/qa/answerDetail?questionDetailId=${prodId}`,
    '17': `/homePage/qa/answerDetail?questionDetailId=${prodId}`,
    '23': `/member/vip/vipUp?type=${prodType}`,
    '24': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '25': `/homePage/course/${courseType == 0 ? 'video' : courseType == 1 ? 'voice' : 'imgText'}?courseId=${prodId}&ckFrom=${ckFrom}`,
    '26': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '27': `/member/vip/vipUp?type=${prodType}`,
    '28': `/member/vip/vipUp?type=${prodType}`,
    '29': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '30': `/homePage/course/${courseType == 0 ? 'video' : courseType == 1 ? 'voice' : 'imgText'}?courseId=${prodId}&ckFrom=${ckFrom}`,
    '31': `/homePage/collage/vipCollage?prodId=${prodId}`,
    '32': `/homePage/collage/vipCollage?prodId=${prodId}`,
    '36': `/activity/activityDetail?ActivityNo=${prodId}`,
    '38': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '41': `/homePage/clockIn/clockInDetail?clockInId=${prodId}`,
    '48': `/homePage/package/packageDetail?combosId=${prodId}`,
    '51': `/homePage/live/liveDetail?liveId=${prodId}`,
    '53': `/activity/activityDetail?ActivityNo=${prodId}&from=reservation`,
    '56': `/homePage/word/wordDetail?dId=${prodId}`,
    '61': `/homePage/package/packageDetail?combosId=${prodId}`,
    '62': `/homePage/package/packageDetail?combosId=${prodId}`,
    '66': `/homePage/course/${courseType == 0 ? 'video' : courseType == 1 ? 'voice' : 'imgText'}?courseId=${prodId}&ckFrom=${ckFrom}`,
    '67': `/homePage/column/columnDetail?extId=${prodId}&ckFrom=${ckFrom}`,
    '68': `/homePage/collage/vipCollage?prodId=${prodId}`,
    '69': `/homePage/collage/vipCollage?prodId=${prodId}`,
    '70': `/homePage/package/packageDetail?combosId=${prodId}`,
    '71': `/homePage/examination/examinationDetail?ExaminationNo=${prodId}`,
    '72': `/homePage/live/liveDetail?liveId=${prodId}`,
    '75': `/homePage/mutuaTest/mutuaTestDetail?mutuaTestId=${prodId}`,
    '76': `/homePage/form?relId=${prodId}`,
    '77': `/homePage/voiceTest/voiceTestDetail?paperMainId=${prodId}`,
    '78': `/homePage/camp/campDetail?campId=${prodId}&ckFrom=${ckFrom}`,
    '86': `/homePage/booking/bookingTime?atId=${prodId}&ckFrom=${ckFrom}`,
    '91': `/homePage/camp/campDetail?campId=${prodId}&ckFrom=${ckFrom}`,
    '103': `/homePage/column/columnDetail?extId=${prodId}&distribution=1&ckFrom=${ckFrom}`,
    '110': `/homePage/course/video?courseId=${prodId}&ckFrom=5`,
    '111': `/homePage/course/voice?courseId=${prodId}&ckFrom=5`,
    '112': `/homePage/course/imgText?courseId=${prodId}&ckFrom=5`,
    '104': `/homePage/column/columnDetail?extId=${prodId}&distribution=1&ckFrom=${ckFrom}`,
    '115': `/homePage/privateClass/classDetail?classId=${prodId}`,
    '116': `/edu/eduDetail?id=${prodId}&ckFrom=${ckFrom}`,
    '124': `/homePage/live/liveDetail?liveId=${prodId}`,
    '125': `/homePage/testPaper/testDetail?testId=${prodId}`,
    '129': `/homePage/itemBank/questionSaleDetail?libraryId=${prodId}&ckFrom=${ckFrom}`,
    '142': `/homePage/ebooks/ebooksDetail?id=${prodId}`,
    '181': `/homePage/circle/circleFeed?id=${prodId}`,
    '185': `/homePage/circle/circleTheme?themeId=${prodId}`,
    '145': `/homePage/ebooks/ebooksDetail?id=${prodId}`,
    '146': `/homePage/camp/campDetail?campId=${prodId}&ckFrom=${ckFrom}`,
    '155': `/mall/shopComments/shopCommentDetail?id=${prodId}`,
    '180': `/homePage/live/livePersonalDetail?liveId=${prodId}`,
    '8075': `/homePage/clockIn/clockInDetail?clockInId=${prodId}`,
    '8076': `/homePage/camp/campDetail?campId=${prodId}&ckFrom=${ckFrom}`,
    '8077': `/homePage/socialGroup/socialGroupInfo?SocialRoomId=${prodId}`,
    '8078': `/activity/activityDetail?ActivityNo=${prodId}&from=reservation`,
    '8079': `/homePage/voiceTest/voiceTestDetail?paperMainId=${prodId}`,
    '8080': `/homePage/mutuaTest/mutuaTestDetail?mutuaTestId=${prodId}`,
    '8081': `/activity/activityDetail?ActivityNo=${prodId}`,
    '8083': `/homePage/ebooks/ebooksDetail?id=${prodId}`,
    '8084': `/homePage/privateClass/classDetail?classId=${prodId}`,
    '9010': `/homePage/socialGroup/socialGroupInfo?SocialRoomId=${prodId}`,
    '9041': `/homePage/clockIn/clockInDetail?clockInId=${prodId}`,
    '9042': `/homePage/itemBank/questionSaleDetail?libraryId=${prodId}&ckFrom=${ckFrom}`,
    '9043': `/edu/eduDetail?id=${prodId}&ckFrom=${ckFrom}`,
    '9044': `/homePage/ebooks/ebooksDetail?id=${prodId}`,
    '9045': `/homePage/live/livePersonalDetail?liveId=${prodId}`,
    '9078': `/homePage/camp/campDetail?campId=${prodId}&ckFrom=${ckFrom}`,
    "5-1": `/homePage/course/courseList${sortType == 0 ? '' : '?sortType=' + sortType}`, //课程列表
    "7-1": "/activity/activityIndex", //活动
    "8-1": "/homePage/datum/datumList", //资料
    "9-1": "/homePage/column/columnList", //专栏
    "10-1": "/homePage/socialGroup/socialGroupList", //社群
    "11-1": "/homePage/examination/examinationList", //测评
    "13-1": `/homePage/microPage/microPage?mId=${prodId}`, //商城
    "15-1": "/homePage/qa/answerLord", //问答
    "41-1": "/homePage/clockIn/clockInList", //打卡
    "51-1": "/homePage/live/liveList", //直播
    "56-1": "/homePage/word/wordList", //词典列表
    "61-1": "/homePage/package/packageList", //知识套餐
    "78-1": "/homePage/camp/campList", //训练营
    "86-1": "/homePage/booking/bookingList", //预约
    "92-1": "/homePage/valueVoucher/list", //优惠券
    "115-1": "/homePage/privateClass/classList", //小班课列表
    "116-1": "/edu/eduList", //教务
    "121-1": "/homePage/collage/collageList", //特惠专区列表
    "125-1": "/homePage/testPaper/testList", //试卷
    "129-1": "/homePage/itemBank/questionList", //题库评
    "137-1": "/homePage/task/taskList", //任务列表
    "170-1": "/homePage/course/courseForenotice", //预告
    "200": `/homePage/shareholder/shCouponDetail?id=${prodId}&rcdId=`, //股东代金券
    "400": `/homePage/microPage/microPage?mId=${prodId}&isPromotedAccount=1`, //子账号推广微页面
    "42": `/homePage/agent/agentDesc?applyType=3`,
    "43": `/homePage/agent/agentDesc?applyType=5`,
    "44": `/homePage/agent/agentDesc?applyType=6`,
    "138": `/homePage/agent/agentDesc?applyType=7`,
    "139": `/homePage/agent/agentDesc?applyType=8`,
    "160": `/homePage/agent/agentDesc?applyType=9`,
    "161": `/homePage/agent/agentDesc?applyType=10`,
    "162": `/homePage/agent/agentDesc?applyType=11`,
    "163": `/homePage/agent/agentDesc?applyType=12`,
    '5000': `/member/myExchange/valuableCoupon?id=${prodId}`,
    '197': `/homePage/collocationBuy/collocationDetail?mId=${prodId}`
  }
  let moreUrl = typeToUrl[prodType];
  if (!moreUrl) {
    return '';
  }
  if (query && typeof query == 'object') {
    for (let key in query) {
      moreUrl += (moreUrl.indexOf('?') == -1 ? '?' : '&') + `${key}=${query[key]}`
    }
  }
  return moreUrl
}
//优惠券或者抵用券或者兑换券的跳转
export function exchangeDoDetail(_this, rId, rType, courseType) {
  // _this, prodType, prodId, courseType, query, isNeedAppPush = 0
  if (rType == 39 || rType == 40) {
    goDetails(_this, global.ckFrom.vip);
  } else if (rType == 38) {
    goDetails(_this, global.ckFrom.column, rId, {
      cId: -1,
      ckFrom: global.ckFrom.column
    }, 0);
  } else if (rType == 85) {
    goDetails(_this, global.ckFrom.exam, rId);
  } else if (rType == 37) {
    goDetails(_this, global.ckFrom.course, rId, {extId: -1, ckFrom: global.ckFrom.course}, courseType, 0);
  } else if (rType == 45) { //知识套餐
    goDetails(_this, global.ckFrom.package, rId);
  } else if (rType == 88) { //交互测评
    goDetails(_this, global.ckFrom.mutuaTest, rId);
  } else if (rType == 89) { //语音测评
    goDetails(_this, global.ckFrom.voiceTest, rId);
  } else if (rType == 90) { //打卡
    goDetails(_this, global.ckFrom.clockIn, rId);
  } else if (rType == 91) { //训练营
    goDetails(_this, global.ckFrom.camp, rId);
  } else if (rType == 94) { //社群
    goDetails(_this, global.ckFrom.social, rId);
  } else if (rType == 95) { //直播
    goDetails(_this, global.ckFrom.live, rId);
  } else if (rType == 122) { //直播
    goDetails(_this, global.ckFrom.privateClass, rId);
  } else if (rType == 96) { //约课
    goDetails(_this, global.ckFrom.activity, rId, {from: 'reservation'});
  } else if (rType == 99) { //活动
    goDetails(_this, global.ckFrom.activity, rId, {from: 'activity'});
  } else if (rType == 106) { //资料
    goDetails(_this, global.ckFrom.datum, rId);
  } else if (rType == 107 && rId !== 0) { //商城
    goDetails(_this, global.ckFrom.shopping, rId);
  } else if (rType == 123) { //面授课
    goDetails(_this, global.ckFrom.edu, rId);
  } else if (rType == 127) { //电子书
    goDetails(_this, global.ckFrom.ebooks, rId);
  } else if (rType == 26) { //通用
    _this.$routerGo(_this, "push", {
      path: '/'
    });
  } else if (rType == 25) {
    _this.$routerGo(_this, "push", {
      path: '/mall/mallIndex'
    });
  } else if (rType == 114) { //预约
    _this.$routerGo(_this, "push", {
      path: '/homePage/booking/bookingList'
    });
  } else if (rType == 140) { //试卷
    goDetails(_this, global.ckFrom.testpPaper, rId);
  } else if (rType == 141) { //题库
    goDetails(_this, global.ckFrom.itemBank, rId);
  } else if (rType == 144) {
    goDetails(_this, global.ckFrom.ebooks, rId);
  } else if (rType == 181) { //圈子
    goDetails(_this, global.ckFrom.circle, rId);
  } else if (rType == 200) { //股东优惠券
    goDetails(_this, global.ckFrom.shareholderPayVoucher, rId);
  }
}
/* 查看课程子分类
  vm this实例
  categoryLevel 分类模板
  categoryTheme 分类样式
  cateId1，cateId2，cateId3  1、2、3级分类id
  name 分类名称
  isNeedAppPush 是否需要app跳转 默认0不需要 1 需要
   */
export function goSubCategory(vm, categoryLevel, categoryTheme, cateId1, cateId2, cateId3, name, isNeedAppPush = 0) {
  let toPath = '';
  let isIOSApp = navigator.userAgent.indexOf("IOSNewApp") > -1;
  let isAndoridNewApp = navigator.userAgent.indexOf("APPAndroidLogin") > -1;
  // 如果是一级分类模板，所有都跳转到商品列表
  // 如果是二级分类模板，此时若是一级分类，则跳转到分类列表，若是二级分类，则是跳转到商品列表
  // 如果是三级分类模板，此时若是一级分类或者是二级分类，则跳转到分类列表，若是三级分类，则是跳转到商品列表
  if (categoryLevel == 1) {
    toPath = `/homePage/course/catDetailList?cateId1=${cateId1}&cateId2=${cateId2}&cateId3=${cateId3}&name=${name}`;
  } else if (categoryLevel == 2) {
    if (cateId1 && cateId2 == 0 && cateId3 == 0) {
      toPath = `/homePage/course/courseCategory?catL1Id=${cateId1}&catL2Id=${cateId2}&catL3Id=${cateId3}&name=${name}`;
    } else {
      toPath = `/homePage/course/catDetailList?cateId1=${cateId1}&cateId2=${cateId2}&cateId3=${cateId3}&name=${name}`;
    }
  } else {
    if (cateId1 && cateId2 && cateId3) {
      toPath = `/homePage/course/catDetailList?cateId1=${cateId1}&cateId2=${cateId2}&cateId3=${cateId3}&name=${name}`;
    } else {
      toPath = `/homePage/course/courseCategory?catL1Id=${cateId1}&catL2Id=${cateId2}&catL3Id=${cateId3}&name=${name}`;
    }
  }
  if (!toPath) {
    return;
  }
  if ((isIOSApp || isAndoridNewApp) && isNeedAppPush == 1) {
    if (isIOSApp) {
      window.webkit.messageHandlers.iosWechatRoute.postMessage(toPath);
    } else {
      let data = {
        path: toPath
      }
      window.androidWechatRoute.doAction(JSON.stringify(data));
    }
  } else {
    vm.$routerGo(vm, "push", {
      path: toPath
    });
  }
}
